<template>
  <view class="profile-page">
    <!-- 个人信息标题 -->
    <text class="personal-info-title">我的主页</text>
    
    <!-- 个人信息 -->
    <view class="user-info">
      <image class="user-avatar" :src="user.avatar" @click="navigateToUserDetail"></image>
      <text class="user-name" @click="navigateToUserDetail">{{ user.name }}</text>
      <view class="user-stats">
        <view class="stat-item">
          <text class="stat-value">{{ user.subscriptions }}</text>
          <text class="stat-label">客户</text>
        </view>
        <view class="stat-item">
          <text class="stat-value">{{ user.followers }}</text>
          <text class="stat-label">日程</text>
        </view>
        <view class="stat-item">
          <text class="stat-value">{{ user.visitors }}</text>
          <text class="stat-label">提议</text>
        </view>
        <view class="stat-item">
          <text class="stat-value">{{ user.favorites }}</text>
          <text class="stat-label">历史</text>
        </view>
      </view>
    </view>

    <!-- 功能按钮 -->
    <view class="features-section">
      <view class="feature-item" @click="navigateToDreamTrack">
        <image src="/static/icons/shuimianjiance.png" class="feature-icon"></image>
        <text class="feature-label">夜班事项</text>
      </view>
      <view class="feature-item">
        <image src="/static/icons/xinlvjiance.png" class="feature-icon"></image>
        <text class="feature-label">爱心提议</text>
      </view>
      <view class="feature-item" @click="navigateToHealthDashboard">
        <image src="/static/icons/jiankangceshi.png" class="feature-icon"></image>
        <text class="feature-label">护理日程</text>
      </view>
    </view>

    <!-- 查看医院介绍按钮 -->
    <view class="membership-section">
      <button class="membership-button" @click="navigateToIntroduction">点击查看颐养中心介绍</button>
    </view>

    <!-- 底部选项 -->
    <view class="settings-section">
      <view class="settings-item" @click="navigateToMyRankings">
        <image src="/static/icons/rank.png" class="settings-icon"></image>
        <text class="settings-label">我的排行</text>
        <image src="/static/icons/right-arrow.png" class="settings-arrow"></image>
      </view>
      <view class="settings-item" @click="navigateToMyPosts">
        <image src="/static/icons/plane.png" class="settings-icon"></image>
        <text class="settings-label">我的发表</text>
        <image src="/static/icons/right-arrow.png" class="settings-arrow"></image>
      </view>
      <view class="settings-item" @click="navigateToMyLikes">
        <image src="/static/icons/heart.png" class="settings-icon"></image>
        <text class="settings-label">我的点赞</text>
        <image src="/static/icons/right-arrow.png" class="settings-arrow"></image>
      </view>
      <view class="settings-item" @click="navigateToSettings">
        <image src="/static/icons/shezhi.png" class="settings-icon"></image>
        <text class="settings-label">设置</text>
        <image src="/static/icons/right-arrow.png" class="settings-arrow"></image>
      </view>
    </view>
  </view>
</template>

<script>
import { getUserInfo } from '@/api/user.js'
export default {
  data() {
    return {
      user: {
        avatar: "/static/images/user1.png",
        name: "--",
        subscriptions: 10,
        followers: 8,
        visitors: 0,
        favorites: 21,
      },
    };
  },
  async onLoad() {
    const userId = uni.getStorageSync('userId');
    if (userId) {
      try {
        const res = await getUserInfo(userId);
        if (res && res.code === 1000 && res.data) {
          this.user.avatar = res.data.avatar;
          this.user.name = res.data.name;
        }
      } catch (e) {}
    }
  },
  async onShow() {
    // 每次页面显示时刷新用户信息
    const userId = uni.getStorageSync('userId');
    if (userId) {
      try {
        const res = await getUserInfo(userId);
        if (res && res.code === 1000 && res.data) {
          this.user.avatar = res.data.avatar;
          this.user.name = res.data.name;
        }
      } catch (e) {}
    }
  },
  methods:{
	  navigateToHealthDashboard(){
		  uni.navigateTo({
		  	url:'/pages/healthDashboard/healthDashboard'
		  })
	  },
	  navigateToDreamTrack(){
	  		  uni.navigateTo({
	  		  	url:'/pages/dreamTrack/dreamTrack'
	  		})
	  },
	  navigateToIntroduction(){
		  uni.navigateTo({
		  	url:'/pages/profile/introduction'
		  })
	  },
	  navigateToMyRankings() {
	    uni.navigateTo({
	      url: '/pages/profile/my-rankings'
	    });
	  },
	  navigateToUserDetail() {
	    uni.navigateTo({
	      url: '/pages/profile/user-detail'
	    });
	  },
    navigateToMyPosts() {
      uni.navigateTo({ url: '/pages/profile/my-posts' });
    },
    navigateToMyLikes() {
      uni.navigateTo({ url: '/pages/profile/my-likes' });
    },
    navigateToSettings() {
      uni.navigateTo({ url: '/pages/profile/settings' });
    }
  }
};
</script>

<style scoped>
.profile-page {
  padding: 20px;
  background-image: url(@/static/images/background1.png);
  background-size: cover; /* 确保背景图覆盖整个页面 */
  background-repeat: no-repeat; /* 防止背景图重复 */
}

.personal-info-title {
	display: flex;
  font-size: 20px;
  justify-content: center;
  color: #fff;
  text-align: center;
  padding-top: 40px;
  margin-bottom: 10px;
  font-weight: bold; /* 使用bold值进行加粗 */
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  padding-top: 10px;
}

.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.user-avatar:active {
  transform: scale(0.95);
}

.user-name {
  font-size: 20px;
  color: #fff;
  margin-bottom: 15px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.user-name:active {
  opacity: 0.8;
}

.user-stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 16px;
  font-weight: bold;
  color: #fff;
}

.stat-label {
  font-size: 14px;
  color: #fff;
}

.features-section {
  display: flex;
  justify-content: space-around;
  margin: 20px 0;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #5bb8ac;
  border-radius: 15%;
  padding: 15px;
}

.feature-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 5px;
}

.feature-label {
  font-size: 14px;
  color: #fff;
}

.membership-section {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.membership-button {
  background-color: transparent;
  color: #5bb8ac;
  width: 85%;
  border: 3px solid #5bb8ac;
  padding: 5px 20px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: bold; /* 使用bold值进行加粗 */
}

.settings-section {
  display: flex;
  flex-direction: column;
  padding-left: 20px;
  padding-top: 10px;
}

.settings-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid #ddd;
}

.settings-icon {
  width: 24px;
  height: 24px;
  margin-right: 10px;
}

.settings-label {
  font-size: 16px;
  color: #333;
  flex: 1;
}

.settings-arrow {
  width: 20px;
  height: 20px;
}

.logout-btn {
  margin: 18px 0 0 0;
  width: 70%;
  align-self: center;
  background: #fff;
  color: #b22222;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: normal;
  padding: 7px 0;
  transition: background 0.2s, color 0.2s;
}
.logout-btn:active {
  background: #ffeaea;
  color: #e60012;
}
</style>
